package com.android.antelopeapp.view.BeautyPic;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;

import com.android.antelopeapp.R;
import com.android.antelopeapp.activity.UploadBPicActivity;

/**
 * Created by phk on 2015/1/3.
 * 控件：用于显示获取图片的方式
 */
public class RequestPicView extends RelativeLayout {
    private FragmentActivity mActivity;
    private View mFromFileBtn;
    private View mFromCameraBtn;

    public RequestPicView(Context context, AttributeSet attrs) {
        super(context, attrs);

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.layout_choose_pic, this, true);

        mFromFileBtn = this.findViewById(R.id.choose_pic_from_file_btn);
        mFromCameraBtn = this.findViewById(R.id.choose_pic_from_camera_btn);
    }

    /**
     * 设置activity，使得获取图片之后可以进行回调
     * activity 一定要实现onActivityResult函数来接收图片
     */
    public void setActivity(FragmentActivity activity) {
        mActivity = activity;
        mFromFileBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //打开系统图库，获取图片
                Intent i = new Intent(mActivity, UploadBPicActivity.class);
                i.putExtra(UploadBPicActivity.REQ_TYPE_CODE, UploadBPicActivity.RESULT_LOAD_IMAGE);
                mActivity.startActivityForResult(i,UploadBPicActivity.REQUEST_UPLOAD_TAGABELIMAGE);
            }
        });

        mFromCameraBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(mActivity, UploadBPicActivity.class);
                i.putExtra(UploadBPicActivity.REQ_TYPE_CODE, UploadBPicActivity.RESULT_CAPTURE_PIC);
                mActivity.startActivityForResult(i,UploadBPicActivity.REQUEST_UPLOAD_TAGABELIMAGE);
            }
        });
    }
}
